package interpreter;

import java.util.HashMap;

/**
 * The CodeTable is a static class that keeps the relationship between the byte codes
 * and the ByteCode class hierarchy.
 * 
 * @author Kristofer Selbekk
 */
public class CodeTable {

    private HashMap table; // The CodeTable itself

    public CodeTable() {
        init();
    }

    /**
     * Sets up the CodeTable
     */
    public void init() {
        table = new HashMap();
        table.put("HALT", "HaltByteCode");
        table.put("POP", "PopByteCode");
        table.put("FALSEBRANCH", "FalseBranchByteCode");
        table.put("GOTO", "GoToByteCode");
        table.put("STORE", "StoreByteCode");
        table.put("LOAD", "LoadByteCode");
        table.put("LIT", "LitByteCode");
        table.put("ARGS", "ArgsByteCode");
        table.put("CALL", "CallByteCode");
        table.put("RETURN", "ReturnByteCode");
        table.put("BOP", "BopByteCode");
        table.put("READ", "ReadByteCode");
        table.put("WRITE", "WriteByteCode");
        table.put("LABEL", "LabelByteCode");
        table.put("DUMP", "DumpByteCode");
    }

    /**
     * Given a recognized byte code, returns the class name of the linked class
     *
     * @param code the byte code
     * @return The name of the class that will be instantiated
     */
    public String get( String code ) {
        return (String) table.get(code);
    }
}
